import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../pages/Home'

Vue.use(VueRouter)
// 重写push
let originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this, location, resolve, reject)
  } else {
    originPush.call(this, location, () => {}, () => {})
  }
}
let originReplace = VueRouter.prototype.replace;

VueRouter.prototype.replace = function (location, resolve, reject) {
  if (resolve && reject) {
    originReplace.call(this, location, resolve, reject)
  } else {
    originReplace.call(this, location, () => {}, () => {})
  }
}

const routes = [{
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      show: true
    }
  },
  {
    path: '/search/:keyword?',
    name: 'Search',
    component: () => import('../pages/Search'),
    meta: {
      show: true
    },


  },
  {
    path: '/logoin',
    name: 'Logoin',
    component: () => import('../pages/Logoin'),
    meta: {
      show: false
    }

  }, {
    path: '*',
    redirect: '/home'
  }

]

const router = new VueRouter({
  routes
})


export default router